package ua.dou.loader;

import android.content.Context;
import android.support.v4.content.AsyncTaskLoader;
import ua.dou.Dou;
import ua.dou.rss.RssReader;

/**
 * Base loader for fetching data.
 * User: David Mayboroda
 */
public abstract class BaseLoader<MD> extends AsyncTaskLoader<Response<MD>>{

    protected RssReader reader;

    protected BaseLoader(Context context) {
        super(context);
        reader = ((Dou)context.getApplicationContext()).getReader();
    }

    @Override
    public Response<MD> loadInBackground() {
        try {
            return new Response<MD>(load());
        } catch (Exception ex) {
            return new Response<MD>(ex);
        }
    }

    public abstract MD load() throws Exception;
}
